package Cola.sort;

import org.junit.jupiter.api.Test;

import java.util.Arrays;

/**
 * @Author Zhang Chao
 * @Date 2021/6/5 17:27
 * @Version 1.0
 */
public class Cola {

}
class ColaEmployee implements Comparable<ColaEmployee> {

    private String empName;
    private int empBirthMonth;
    private int month;



    public ColaEmployee(String empName, int empBirthMonth, int month) {
        this.empName = empName;
        this.empBirthMonth = empBirthMonth;
        this.month = month;
    }

    public String getEmpName() {
        return empName;
    }

    public void setEmpName(String empName) {
        this.empName = empName;
    }

    public int getEmpBirthMonth() {
        return empBirthMonth;
    }

    public void setEmpBirthMonth(int empBirthMonth) {
        this.empBirthMonth = empBirthMonth;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }


    public double getSalary() {

        double salary = 0.0;

        if (month == empBirthMonth) {
            salary = 100;
        }

        return salary;
    }

    @Override
    public int compareTo(ColaEmployee employee) {

        int i = 0;

        if (employee != null) {
            if (this.getSalary() > employee.getSalary()) {
                i = 1;
            } else if (this.getSalary() < employee.getSalary()) {
                i = -1;
            }
        }

        return i * -1;
    }
}

class Company {

    private int month;

    private ColaEmployee[] employees;

    // 行为
    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public ColaEmployee[] getEmployees() {
        return employees;
    }

    public void setEmployees(ColaEmployee[] employees) {
        this.employees = employees;
    }



    public void sortbySalary(){

        Arrays.sort(employees);
    }



    public void printMonthSalary() {

        if (employees != null && employees.length > 0) {

            for (ColaEmployee colaEmployee : employees) {
                System.out.println("员工" + colaEmployee.getEmpName() + "的" + colaEmployee.getMonth() + "月份工资为：" +
                        colaEmployee.getSalary());
            }
        }
    }
}
class HourlyEmployee extends ColaEmployee {

    private double salaryPerHour;
    private double totalHoursPermonth;


    public HourlyEmployee(String empName, int empBirthMonth, int month, double salaryPerHour, double totalHoursPermonth) {
        super(empName, empBirthMonth, month);
        this.salaryPerHour = salaryPerHour;
        this.totalHoursPermonth = totalHoursPermonth;
    }

    @Override
    public double getSalary() {

        double salarySum = salaryPerHour * totalHoursPermonth;

        salarySum += (totalHoursPermonth - 160) > 0 ? (totalHoursPermonth - 160) * 0.5 * salaryPerHour : 0;
        return salarySum + super.getSalary();
    }
}
class SalariedEmployee extends ColaEmployee {

    private double salaryPerMonth;



    public SalariedEmployee(String empName, int empBirthMonth, int month, double salaryPerMonth) {
        super(empName, empBirthMonth, month);
        this.salaryPerMonth = salaryPerMonth;
    }

    @Override
    public double getSalary() {

        return salaryPerMonth + super.getSalary();
    }
}
class SalesEmployee extends ColaEmployee {

    private double saleTotal;
    private double saleRate;



    public SalesEmployee(String empName, int empBirthMonth, int month, double saleTotal, double saleRate) {
        super(empName, empBirthMonth, month);
        this.saleTotal = saleTotal;
        this.saleRate = saleRate;
    }

    @Override
    public double getSalary() {
        return saleRate * saleTotal + super.getSalary();
    }
}
class TestDriver {

    public static void main(String[] args) {

        ColaEmployee[] employees = {
                new SalariedEmployee("张三", 4, 5, 5000),
                new HourlyEmployee("李四", 5, 5, 60, 180),
                new SalesEmployee("王五", 5, 5, 100000, 0.06),
                new SalariedEmployee("赵六", 3, 5, 7000)
        };




        Company company = new Company();

        company.setEmployees(employees);


        company.sortbySalary();


        company.printMonthSalary();

    }
}